﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace MvcEngine.Mvc.View.Controls
{
    public class CollapsablePanel : IDisposable
    {
        #region Private fields
        private bool _disposed;
        private readonly HttpResponseBase _httpResponse;

        #endregion

        #region Constructors
        public CollapsablePanel(HttpResponseBase httpResponse)
        {
            if (httpResponse == null)
            {
                throw new ArgumentNullException("httpResponse");
            }
            this._httpResponse = httpResponse;
        }

        #endregion

        #region Public methods
        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        public void EndForm()
        {
            this.Dispose(true);
        } 
        #endregion

        #region Protected methods
        protected virtual void Dispose(bool disposing)
        {
            if (!this._disposed)
            {
                this._disposed = true;
                this._httpResponse.Write("</div></div>");
            }
        } 
        #endregion
    }
}
